<template>
  <el-row :gutter="10">
    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
      <div class="grid-content bg-purple">
        <div class="app-contain">
          <!-- 第二行 -->
          <div class="two">
            <!-- 第一排搜索卡片 -->
            <el-card class="box-card">
              <el-row
                style="font-size: 15px; line-height: 2em; color: #909399"
                :gutter="60"
              >
                <el-col :span="6">
                  <div class="two_left"></div>
                </el-col>

                <el-col :span="18">
                  <el-col :span="24" style="">
                    <div class="two_right">
                      所属部门:
                      <!-- element-ui官网Radio单选框的使用中，基础用法使用的是label，radio的值是字符串；单选框组el-radio-group使用的是:label，radio的值是数字 -->
                      <el-radio-group
                        v-model="formInLine.radio"
                        @change="search"
                      >
                        <el-radio-button label="0">全部</el-radio-button>
                        <el-radio-button
                          v-for="dept in depts"
                          :key="dept.index"
                          :label="dept.deptId"
                          >{{ dept.deptName }}</el-radio-button
                        >
                      </el-radio-group>
                      <hr />
                    </div>
                    <div class="search">
                      <div style="float: left">
                        培训名称:<el-input
                          v-model="itemtitle"
                          placeholder="请输入内容"
                          style="width: 35%"
                        ></el-input>
                        培训状态:
                        <el-select v-model="Svalue" placeholder="请选择">
                          <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          >
                          </el-option>
                        </el-select>
                      </div>
                      <div style="float: left">
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          @click="search"
                          >搜索</el-button
                        >
                      </div>
                    </div>
                  </el-col>
                </el-col>
              </el-row>
            </el-card>

            <!-- 我的审批 -->
            <div class="three">
          <!--    <div class="three_left">
                <el-card class="box-card">
                  <div slot="header" class="clearfix">
                    <span><h3>我的审批</h3></span>
                  </div>
                  <div style="margin-top: 10px">
                    
                    <el-popover
                      placement="right"
                      width="800"
                      trigger="click"
                      style="height: 800px"
                    >
                      <div style="height: 500px">
                        <div
                          v-show="planschedule.length == 0"
                          style="
                            height: 100%;
                            text-align: center;
                            line-height: 500px;
                          "
                        >
                          无内容
                        </div>
                        <div v-for="plan in planschedule" :key="plan">
                          <el-card class="box-card" style="margin-bottom: 10px">
                            <div slot="header" class="clearfix">
                              <span style="font-size: 20px">培训计划</span>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                审批人:{{ plan.approver }}
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                当前进度:审批中
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver === null"
                              >
                                已审核
                              </div>
                            </div>
                            <div style="clear: both; float: left">
                              计划标题:{{ plan.planTitle }}
                            </div>

                            <div style="float: right">
                              发起时间{{ plan.planStarttime }}
                            </div>
                          </el-card>
                        </div>
                      </div>
                      <el-button slot="reference" @click="findMyApproved"
                        >已审核</el-button
                      >
                    </el-popover>
                  </div>
                  <hr />
                  <div style="margin-top: 50px">
                    
                    <el-popover placement="right" width="800" trigger="click">
                      <div style="height: 500px">
                        <div
                          v-show="planschedule.length == 0"
                          style="
                            height: 100%;
                            text-align: center;
                            line-height: 500px;
                          "
                        >
                          无内容
                        </div>

                        <div v-for="plan in planschedule" :key="plan">
                          <el-card class="box-card" style="margin-bottom: 10px">
                            <div slot="header" class="clearfix">
                              <span style="font-size: 20px">培训计划</span>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                审批人:{{ plan.approver }}
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                当前进度:审批中
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver === null"
                              >
                                已审核
                              </div>
                            </div>
                            <div style="clear: both; float: left">
                              计划标题:{{ plan.planTitle }}
                            </div>

                            <div style="float: right">
                              发起时间{{ plan.planStarttime }}
                            </div>
                          </el-card>
                        </div>
                      </div>
                      <el-button slot="reference" @click="findMyApproveNow"
                        >未审核</el-button
                      >
                    </el-popover>
                  </div>
                  <hr />
                  <div style="margin-top: 50px; margin-bottom: 100px">
                    
                    <el-popover placement="right" width="800" trigger="click">
                      <div style="height: 500px">
                        <div
                          v-show="planschedule.length == 0"
                          style="
                            height: 100%;
                            text-align: center;
                            line-height: 500px;
                          "
                        >
                          无内容
                        </div>
                        <div v-for="plan in planschedule" :key="plan">
                          <el-card class="box-card" style="margin-bottom: 10px">
                            <div slot="header" class="clearfix">
                              <span style="font-size: 20px">培训计划</span>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                审批人:{{ plan.approver }}
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver !== null"
                              >
                                当前进度:审批中
                              </div>
                              <div
                                style="float: right; padding: 3px 0"
                                v-show="plan.approver === null"
                              >
                                已审核
                              </div>
                            </div>
                            <div style="clear: both; float: left">
                              计划标题:{{ plan.planTitle }}
                            </div>

                            <div style="float: right">
                              发起时间{{ plan.planStarttime }}
                            </div>
                          </el-card>
                        </div>
                      </div>
                      <el-button slot="reference" @click="planSchedule"
                        >审批进度</el-button
                      >
                    </el-popover>
                  </div> 
                </el-card>
              </div>-->
              <div class="three_right">
                <div v-for="plan in planList" :key="plan.index">
                  <el-card class="box-card" style="margin-bottom: 10px">
                    <div slot="header" class="clearfix">
                      <span style="font-size: 20px">{{ plan.planTitle }}</span>
                      <!-- <el-button
                        style="float: right; padding: 3px 0"
                        type="text"
                        >查看详情</el-button
                      > -->
                      <!-- 查看详情 -->
                      <el-popover placement="left" width="800" trigger="click">
                        <el-row>

                        <el-col :span="12">
                        <el-form>
                          <el-form-item label="计划标题:">
                            <span>{{ plandetail.planTitle }}</span>
                          </el-form-item>
                          <el-form-item label="需求部门:">
                            <span>{{ plandetail.planFor }}</span>
                          </el-form-item>
                          <el-form-item label="收集部门:">
                            <span>{{ plandetail.planCollect }}</span>
                          </el-form-item>
                          <el-form-item label="总预算:">
                            <span>{{ plandetail.planMoney }}</span>
                            
                          </el-form-item>
                          <el-form-item label="计划详情:">
                            <span><a :href="plandetail.planContent" :download="plandetail.planContent" >点击下载</a></span>
                          </el-form-item>
                          <el-form-item label="发布人:">
                            <span>{{ plandetail.pubulisher }}</span>
                          </el-form-item>
                          <el-form-item label="发布时间:">
                            <span>{{ (plandetail.planStarttime || "").split("T")[0] }}</span>
                          </el-form-item>
                          <el-form-item label="审核进度:" v-if="plandetail.etmsApproveRecord != null">
                            <span>当前审核人:{{ plandetail.etmsApproveRecord.approver }}</span>
                            <span style="margin-left:20px">截止时间:{{(plandetail.etmsApproveRecord.approveEndtime || "").split("T")[0]}}</span>
                          </el-form-item>
                          <el-form-item label="计划状态:" v-show="plandetail.etmsApproveRecord == null">
                            <span style="color:green" v-show="plandetail.planPass == 'y'">已通过审核</span>
                            <span style="color:red" v-show="plandetail.planPass == 'n'">未通过审核</span>
                          </el-form-item>
                        </el-form>
                        </el-col>
                        <el-col :span="12">
                        <el-form >
                          <el-form-item label=" 预算详情:" >
                            <span>预算去向</span><span style="margin-left:80px">数目</span>
                          </el-form-item>
                          <el-form-item v-for="budget in plandetail.etmsPlanBudgetList" :key="budget.index">
                            <span style="margin-left:70px">{{budget.budgetName}}</span><span style="float:right;margin-right:140px">{{budget.budgetNum}}</span>
                          </el-form-item>
                        </el-form>
                        </el-col>
                        </el-row>
                        <el-button
                          slot="reference"
                          @click="planSchedule(plan.planId)"
                          style="float: right; padding: 3px 0"
                          >查看详情</el-button
                        >
                      </el-popover>
                    </div>
                    <div style="float: left;clear:both">需求部门:{{ plan.planFor }}</div>
                    <div style="float: left;margin-left:50px">
                      收集部门:{{ plan.planCollect }}
                    </div>
                    <div style="float: right;margin-bottom:20px">
                      发起时间:{{ (plan.planStarttime || "").split("T")[0] }}
                    </div>
                  </el-card>
                </div>
                <div class="block">
                  <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="currentPage3"
                    :page-size="3"
                    layout="prev, pager, next, jumper"
                    :total="total"
                  >
                  </el-pagination>
                </div>
              </div>
            </div>
          </div>
        </div></div
    ></el-col>
  </el-row>
</template>

<script>
import { findAllPlan } from "@/api/plan";
import { findBySelect } from "@/api/plan";
import { findAllDept } from "@/api/plan";
import { findPlanSchedule } from "@/api/plan";
import { findMyApproved } from "@/api/plan";
import { findMyApproveNow } from "@/api/plan";
import {findPlanDetail} from "@/api/plan";
export default {
  // el: ".app-contain",
  data() {
    return {
      
      planschedule: [], //审批进度显示
      planList: [],
      currentPage: 1,
      itemSum: "0",
      total: 0,
      currentPage3: 1,
      depts: [],
      itemtitle: "",
      options: [
        {
          value: "",
          label: "不限",
        },
        {
          value: "n",
          label: "未审核",
        },
        {
          value: "y",
          label: "已审核",
        },
      ],
      Svalue: "",
      formInLine: {
        page: 1,
        id: 1,
        limit: 10,
        radio: 1,
      },
      plandetail: {
        etmsApproveRecord:{
          approver:""
        }
      },
    };
  },
  created() {
    this.getdata();
  },

  methods: {
    getdata() {
      this.userId = this.$store.getters.userId;
      findAllPlan(1)
        .then((res) => {
          this.formInLine.radio = 0;
          this.total = res.data.total;
          this.planList = res.data.list;
        })
        .catch();
      findAllDept()
        .then((res) => {
          console.log(res);
          this.depts = res.data;
        })
        .catch();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      if (this.formInLine.radio == 0) {
        console.log(this.itemtitle);
        findBySelect({
          etmsPlan: {
            planTitle: this.itemtitle,
            planStatus: this.Svalue,
          },
          startPage: val,
        })
          .then((res) => {
            this.total = res.data.total;
            this.planList = res.data.list;
          })
          .catch();
      } else {
        console.log(this.depts[this.formInLine.radio - 1].deptName);
        
        findBySelect({
          etmsPlan: {
            planFor: this.depts[this.formInLine.radio - 1].deptName,
            planTitle: this.itemtitle,
            planStatus: this.Svalue,
          },
          startPage: val,
        })
          .then((res) => {
            this.total = res.data.total;
            this.planList = res.data.list;
          })
          .catch();
      }
      console.log(`当前页: ${val}`);
    },
    // 类别改变
    search(val) {
      console.log(this.formInLine.radio);
      console.log(this.itemtitle);
      if (this.formInLine.radio == 0) {
        console.log(this.itemtitle);
        findBySelect({
          etmsPlan: {
            planTitle: this.itemtitle,
            planStatus: this.Svalue,
          },
          startPage: 1,
        })
          .then((res) => {
            this.total = res.data.total;
            this.planList = res.data.list;
          })
          .catch();
      } else {
        console.log(this.depts[this.formInLine.radio - 1].deptName);
        console.log(this.itemtitle +"sdwasd")
        findBySelect({
          etmsPlan: {
            planFor: this.depts[this.formInLine.radio - 1].deptName,
            planTitle: this.itemtitle,
            planStatus: this.Svalue,
          },
          startPage: 1,
        })
          .then((res) => {
            console.log(res)
            this.total = res.data.total;
            this.planList = res.data.list;
          })
          .catch();
      }
    },
    planSchedule(planId) {
      
      findPlanDetail(planId).then((res) => {
        console.log(res);
        this.plandetail = res.data;
        console.log(this.plandetail)
      }).catch;
    },
    findMyApproveNow() {
      findMyApproveNow(this.userId).then((res) => {
        console.log(res);
        this.planschedule = res.data;
      }).catch;
    },
    findMyApproved() {
      findMyApproved(this.userId).then((res) => {
        console.log(res);
        this.planschedule = res.data;
      }).catch;
    },
    
  },
};
</script>

<style>
.app-contain {
  width: 100%;
  height: 800px;
  background-color: rgb(229, 229, 238);
}
.el-breadcrumb {
  font-size: 20px;
  line-height: 4;
}
.two {
  width: 80%;
  clear: both;
  margin: 0 auto;
  margin-top: 0px;
}
.two_left {
  float: left;
  width: 300px;
  height: 150px;
  font-size: 30px;
  color: #fff;
  position: relative;
  background-image: url(../../img/计划主页.jpeg);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-background-size: 300px 150px;
}
.two_right {
  margin-top: 25px;
}
.three {
  clear: both;
}
.button {
  padding: 0;
  float: right;
  margin-top: 75px;
  margin-right: 50px;
  width: 130px;
  height: 80px;
  font-size: 1.5em;
}
.description {
  float: left;
  margin-top: 45px;
  margin-left: 30px;
}
.men {
  font-size: 40px;
  letter-spacing: 10px;
  position: absolute;
  top: 50%;
  left: 30%;
}
#words {
  margin-top: 1.67em;
  margin-left: 120px;
}
.teo_left {
  height: 100%;
  background-color: yellow;
  width: 300px;
  margin-right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.two_left > div:first-child {
  width: 100%;
  height: 150px;
  font-size: 30px;
  color: #fff;
  position: relative;
  background-image: url(../../img/计划主页.jpeg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.two_left > div:first-child > span:last-child {
  font-size: 16px;
  position: absolute;
  bottom: 10px;
  right: 10px;
}
.item {
  float: left;
  margin-left: 30px;
}
.three {
  clear: both;
  margin: 0 auto;
  margin-top: 25px;
}
.three_left {
  float: left;
  width: 27%;
}
.three_right {
  height: 100px;
  float: right;
  width: 100%;
}
.block {
  width: 75%;
  margin: 0 auto;
  float: right;
}
a:link {
    color:#1100ff;
    text-decoration:underline;
}

    
a:hover {
    color:#8a132d;
    text-decoration:none;
    }
    
a:active {
    color:#FFFFFF;
    text-decoration:none;
}
</style>